package cn.udrm.elasticsearch.fileread;

import java.io.*;

/**
 * 读取文本内容
 * @author xurongbei
 */
public class TXTReadContent {

    public static String getTxtContent(File file) throws IOException {
        StringBuffer stringBuffer=new StringBuffer();
        FileInputStream fis=new FileInputStream(file);
        InputStreamReader reader = new InputStreamReader(fis,"GBK");//考虑到编码格式
        BufferedReader br = new BufferedReader(reader);//构造一个BufferedReader类来读取文件
        String s = null;
        while((s = br.readLine())!=null){//使用readLine方法，一次读一行
            stringBuffer.append(System.lineSeparator()+s);
        }
        br.close();
        fis.close();
        return stringBuffer.toString();
    }
}
